package com.wuyong.chapter7;

import java.util.*;
import java.util.Set;

public class LeetCode349 {

    public static void main(String[] args) {


    }

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new TreeSet<>();

        for (Integer i : nums1) {
            set1.add(i);
        }
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (Integer i : nums2) {
            if (set1.contains(i)) {
                arrayList.add(i);
                set1.remove(i);
            }
        }
        int[] res = new int[arrayList.size()];
        for (int i = 0; i < arrayList.size(); i++) {
            res[i] = arrayList.get(i);
        }

        return res;
    }
}
